package com.lanou.zakerproject.subscribe;

import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.BaseActivity;
import com.lanou.zakerproject.base.VolleySingleton;
import com.lanou.zakerproject.tool.GsonRequest;

/**
 * Created by dllo on 16/1/27.
 */
public class CoverActivity extends BaseActivity {
    private ImageView cover_img, cover_down;
    private String URL = "http://iphone.myzaker.com/zaker/cover.php?_appid=AndroidPhone&_bsize=1080_1920&_dev=97&_lat=4.9E-324&_lng=4.9E-324&_mcode=D79B3480&_net=wifi&_nudid=7891a15eb7d34771&_os=5.1_GoogleNexus5-5.1.0-API22-1080x1920&_os_name=GoogleNexus5-5.1.0-API22-1080x1920&_udid=7891a15eb7d34771&_v=6.4.5&_version=6.44&api_version=3.3";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cover);
        cover_img = (ImageView) findViewById(R.id.cover_img);
        cover_down = (ImageView) findViewById(R.id.cover_down);
        getRequsetData(URL);
    }

    /**
     * 解析数据的方法
     * @param urls 接口
     */
    private void getRequsetData(String urls) {
        GsonRequest<CoverData> gsonRequest = new GsonRequest<>(urls, CoverData.class, new Response.Listener<CoverData>() {
            @Override
            public void onResponse(CoverData response) {
                ImageLoader.ImageListener listener = ImageLoader.getImageListener(cover_img, R.mipmap.ic_launcher, R.mipmap.default_img_nonet);
                VolleySingleton.getImageLoader().get(response.getData().getPic(), listener);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        VolleySingleton.getInstance()._addRequest(gsonRequest);
    }
}